package com.riant.controller;


import com.riant.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping(path = "/v1/id", method = RequestMethod.GET)
    @ResponseBody
    public User getUser(@RequestParam("id")  int id) {
        User user = new User();
        user.setName("zhangsan");
        user.setAge((short) 10);
        return user;
    }

    @RequestMapping(path = "/v1/map", method = RequestMethod.POST)
    @ResponseBody
    public User getUserByMap(@RequestBody Map map) {
        System.out.println(map.get("id"));
        User user = new User();
        user.setName("zhangsan");
        user.setAge((short) 10);
        return user;
    }

    @RequestMapping(path = "/v1/update", method = RequestMethod.POST)
    @ResponseBody
    public User updateMap(@RequestBody Map map) {
        System.out.println(map.get("id"));
        User user = new User();
        user.setName("zhangsan");
        user.setAge((short) 10);
        return user;
    }
    @RequestMapping(path = "/v2/update", method = RequestMethod.POST)
    @ResponseBody
    public User update(@RequestBody User user) {
        System.out.println(user.toString());
        User user1 = new User();
        user1.setName("zhangsan");
        user1.setAge((short) 10);
        return user1;
    }
}
